require('dotenv').config();
require('./config/passport');

const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const passport = require('passport');
const oauthServer = require('./routes/oauth');

const app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(session({
    secret: process.env.SESSION_SECRET,
    resave: false,
    saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());

app.use('/oauth', oauthServer);

app.get('/', (req, res) => {
    res.send('OAuth 2.0 Server');
});

const port = process.env.SERVER_PORT || 7000;
const host = process.env.SERVER_HOST
app.listen(port, host, () => {
    console.log(`Server listening on http://${host}:${port}/`);
});